package com.example.qxfw.dlqx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.zy.MaxPowerLoadFcst;
import com.example.qxfw.dlqx.mapper.MaxPowerLoadFcstMapper;
import com.example.qxfw.dlqx.service.MaxPowerLoadFcstService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;


@Service
public class MaxPowerLoadFcstServiceImpl implements MaxPowerLoadFcstService {

    @Autowired
    private MaxPowerLoadFcstMapper maxPowerLoadFcstMapper;

    @Override
    public List<MaxPowerLoadFcst> listByParams(String dateChar, String timeChar, String nTimes) {
        return maxPowerLoadFcstMapper.selectList(Wrappers.<MaxPowerLoadFcst>lambdaQuery()
                .eq(MaxPowerLoadFcst::getDatechar, Timestamp.valueOf(dateChar))
                .eq(MaxPowerLoadFcst::getTimechar,timeChar)
                .eq(MaxPowerLoadFcst::getNtimes,nTimes));
    }

    @Override
    public List<MaxPowerLoadFcst> listByParams(String dateChar1, String dateChar2) {
        return maxPowerLoadFcstMapper.selectList(Wrappers.<MaxPowerLoadFcst>lambdaQuery()
                .between(StringUtils.isNotBlank(dateChar2),MaxPowerLoadFcst::getDatechar,Timestamp.valueOf(dateChar1),Timestamp.valueOf(dateChar2))
                .eq(StringUtils.isBlank(dateChar2),MaxPowerLoadFcst::getDatechar,Timestamp.valueOf(dateChar1))
                .orderByAsc(MaxPowerLoadFcst::getDatechar));
    }

    @Override
    public Integer update(MaxPowerLoadFcst maxPowerLoadFcst) {
        return maxPowerLoadFcstMapper.update(maxPowerLoadFcst,Wrappers.<MaxPowerLoadFcst>lambdaUpdate()
                .eq(MaxPowerLoadFcst::getDatechar, new Timestamp(maxPowerLoadFcst.getDatechar().getTime()))
                .eq(MaxPowerLoadFcst::getTimechar,maxPowerLoadFcst.getTimechar())
                .eq(MaxPowerLoadFcst::getNtimes,maxPowerLoadFcst.getNtimes()));
    }

    @Override
    public Integer save(MaxPowerLoadFcst maxPowerLoadFcst) {
        return maxPowerLoadFcstMapper.insert(maxPowerLoadFcst);
    }




    @Override
    public List<MaxPowerLoadFcst> selectByDateOfMaxPowerLoadFcst(Date datechar) {
        return maxPowerLoadFcstMapper.selectList(new LambdaQueryWrapper<MaxPowerLoadFcst>()
        .eq(datechar != null, MaxPowerLoadFcst::getDatechar, datechar));
    }
}
